/**
 * 	 Copyright (c) 2008, 2009 Lukas Zaruba
 * 
 *   This file is part of UniAnalyzer (Universal Analyzer).
 *
 *   UniAnalyzer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   UniAnalyzer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with UniAnalyzer. If not, see <http://www.gnu.org/licenses/>.
 */


package net.zarubsys.unianalyzer.testing.performance;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.zarubsys.unianalyzer.dataminers.lpt.ILptDataMiner;
import net.zarubsys.unianalyzer.dataminers.lpt.gui.parameterObject.LPTMeasuringSettings;
import net.zarubsys.unianalyzer.dataminers.lpt.gui.parameterObject.MeasuringSettingsFactory;
import net.zarubsys.unianalyzer.dataminers.lpt.internal.impl.LptDataMiner;
import net.zarubsys.unianalyzer.dataminers.lpt.results.IResult;
import net.zarubsys.unianalyzer.dataminers.lpt.wizard.utils.ParameterObjectParser;

import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;

/**
 * Application
 *
 * @author  &lt;A HREF=&quot;mailto:lukas.zaruba@gmail.com&quot;&gt;Lukas Zaruba&lt;/A&gt
 * @version $Revision$ $Date$
 */
public class Application implements IApplication {

	private static final int MEASURING_COUNT = 10;

	public Object start(IApplicationContext context) throws Exception {
		IResult[] results;
		System.out.println("UniAnalyzer Performance Testing");
		System.out.println(SimpleDateFormat.getInstance().format(new Date()));
		System.out.println("===================START==================");
		System.out.println("Getting default measuring settings...");
		try {
			LPTMeasuringSettings ms = MeasuringSettingsFactory.getInstance().getDefaultSettings();
			ILptDataMiner miner = LptDataMiner.getInstance();
			System.out.println("Allocating the result area...");
			results = new IResult[MEASURING_COUNT];
			for (int i = 0; i < results.length; i++) {
				Thread.sleep(250);
				System.out.println("Starting analysis no." + i + "...");
				results[i] = miner.analyze(new ParameterObjectParser(ms));
			}
		} catch (Exception e) {
			System.out.println("Error occured during the testing!");
			e.printStackTrace(System.out);
			return 1;
		}
		System.out.println("Testing finished sucessfuly");
		System.out.println("===================RESULT==================");
		for (int i = 0; i < results.length; i++) {
			IResult r = results[i];
			String freq = NumberFormat.getInstance().format(r.getRealFrequency());
			System.out.println(i + ": " + freq + " Hz");
		}
		return 0;
	}

	public void stop() {
		// TODO Auto-generated method stub

	}

}


/*
 * $Log$
 */